home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / lightwave / arexx_macros / psurf.lwm < prev    next >
Text File  |  1996-12-09  |  4KB  |  182 lines

  1. /* Parametric Surface
  2.  * Create a bunch of polys in LightWave
  3.  * By Fredrik Öhrn
  4.  *
  5.  */
  6.  
  7. numeric digits 6
  8.  
  9. call addlib "LWModelerARexx.port", 0
  10. call addlib "rexxmathlib.library", 0, -30, 0
  11.  
  12. signal on error
  13. signal on syntax
  14.  
  15. dfile = 'ENV:PSurf.state'
  16. pfile = ''
  17.  
  18. /* Defaults */
  19. umin = 0
  20. umax = 6.283
  21. ustep = 20
  22. vmin = 0
  23. vmax = 6.283
  24. vstep = 10
  25. ptype = 2
  26. FofUV.0 = "(1+.5*cos(v))*cos(u)"
  27. FofUV.1 = "(1+.5*cos(v))*sin(u)"
  28. FofUV.2 = ".5*sin(v)"
  29.  
  30. if (exists(dfile)) then do
  31.     if (~open(state, dfile, 'R')) then break
  32.     parse value readln(state) with umin umax ustep vmin vmax vstep ptype .
  33.     do i = 0 to 2
  34.         FofUV.i = readln(state)
  35.     end i
  36.     call close state
  37. end
  38.  
  39. do forever
  40.     call req_begin 'Parametric Surface'
  41.  
  42.     id_mes = req_addcontrol("Make Surface using", 'T', "custom equations X(u, v), Y(u, v), Z(u, v)")
  43.     id_umin = req_addcontrol("u min ", 'n', 0)
  44.     id_umax = req_addcontrol("u max ", 'n', 0)
  45.     id_ustep = req_addcontrol("No of steps", 'n')
  46.     id_vmin = req_addcontrol("v min ", 'n', 0)
  47.     id_vmax = req_addcontrol("v max ", 'n', 0)
  48.     id_vstep = req_addcontrol("No of steps", 'n')
  49.     id_fn.0 = req_addcontrol("X(u, v) = ", 'S', 40)
  50.     id_fn.1 = req_addcontrol("Y(u, v) = ", 'S', 40)
  51.     id_fn.2 = req_addcontrol("Z(u, v) = ", 'S', 40)
  52.     id_ptype = req_addcontrol("Create ", 'CH', "Points Polys Quads")
  53.     id_action = req_addcontrol("", 'CH', "Use Load Save")
  54.     id_file = req_addcontrol("Parameter file ", 'T', pfile)
  55.  
  56.     call req_setval id_umin, umin
  57.     call req_setval id_umax, umax
  58.     call req_setval id_ustep, ustep
  59.     call req_setval id_vmin, vmin
  60.     call req_setval id_vmax, vmax
  61.     call req_setval id_vstep, vstep
  62.     do i = 0 to 2
  63.         call req_setval id_fn.i, FofUV.i
  64.     end i
  65.     call req_setval id_ptype, ptype
  66.     call req_setval id_action, 1
  67.  
  68.     if (~req_post()) then do
  69.         call req_end
  70.         exit
  71.     end
  72.  
  73.     umin = req_getval(id_umin)
  74.     umax = req_getval(id_umax)
  75.     ustep = req_getval(id_ustep)
  76.     vmin = req_getval(id_vmin)
  77.     vmax = req_getval(id_vmax)
  78.     vstep = req_getval(id_vstep)
  79.     do i = 0 to 2
  80.         FofUV.i = req_getval(id_fn.i)
  81.     end i
  82.     ptype = req_getval(id_ptype)
  83.     action = req_getval(id_action)
  84.  
  85.     /* Load params */
  86.     if action = 2 then do
  87.         pfile = getfilename("Load Parameter File", '', pfile)
  88.         if fil ~= '(none)' then do
  89.             if (~open(state, pfile, 'R')) then break
  90.             parse value readln(state) with umin umax ustep vmin vmax vstep ptype .
  91.             do i = 0 to 2
  92.                 FofUV.i = readln(state)
  93.             end i
  94.             call close state
  95.  
  96.             call req_setval id_umin, umin
  97.             call req_setval id_umax, umax
  98.             call req_setval id_ustep, ustep
  99.             call req_setval id_vmin, vmin
  100.             call req_setval id_vmax, vmax
  101.             call req_setval id_vstep, vstep
  102.             do i=0 to 2
  103.                 call req_setval id_fn.i, FofUV.i
  104.             end i
  105.             call req_setval id_ptype, ptype
  106.             call req_setval id_action, 1
  107.         end
  108.     end
  109.  
  110.     /* Save params */
  111.     if action = 3 then do
  112.         pfile = getfilename("Save Parameter File", '', pfile)
  113.         if pfile ~= '(none)' then do
  114.             if (~open(state, pfile, 'W')) then break
  115.             call writeln state, umin umax ustep vmin vmax vstep ptype
  116.             do i = 0 to 2
  117.                 call writeln state, FofUV.i
  118.             end i
  119.             call close state
  120.             call req_setval id_action, 1
  121.         end
  122.     end
  123.     call req_end
  124.  
  125.     if action ~= 1 then iterate
  126.  
  127.     if (open(state, dfile, 'W')) then do
  128.         call writeln state, umin umax ustep vmin vmax vstep ptype
  129.         do i=0 to 2
  130.             call writeln state, FofUV.i
  131.         end i
  132.         call close state
  133.     end
  134.  
  135.     call meter_begin (ustep+1)*(vstep+1), 'Generating Points'
  136.     call add_begin
  137.  
  138.     du = (umax-umin)/ustep
  139.     dv = (vmax-vmin)/vstep
  140.     do u=umin to umax by du
  141.         do v=vmin to vmax by dv
  142.             interpret 'X='||FofUV.0
  143.             interpret 'Y='||FofUV.1
  144.             interpret 'Z='||FofUV.2
  145.             call add_point(X Y Z)
  146.             call meter_step
  147.         end v
  148.     end u
  149.     call meter_end
  150.  
  151.     if ptype > 1 then do
  152.         call meter_begin (ustep+1)*(vstep+1), 'Adding Polygons'
  153.         if ptype = 2 then do
  154.             do u = 1 to ustep*(vstep+1) by vstep+1
  155.                 do v = u to u+vstep-1
  156.                     call add_polygon(v||' '||(v+1)||' '||(v+vstep+2)||' '||(v+vstep+1))
  157.                     call meter_step
  158.                 end v
  159.             end u
  160.         end
  161.         if ptype = 3 then do
  162.             do u = 1 to ustep*(vstep+1) by vstep+1
  163.                 do v = u to u+vstep-1
  164.                     call add_quad(v||' '||(v+1)||' '||(v+vstep+2)||' '||(v+vstep+1))
  165.                     call meter_step
  166.                 end v
  167.             end u
  168.         end
  169.         call meter_end
  170.     end
  171.     call add_end
  172.     call end_all
  173.     exit
  174.  
  175. end /* Forever */
  176.  
  177. syntax:
  178. error:
  179.     call end_all
  180.     call notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  181.     exit
  182.